import listStatus from '../../tabBar/public/js/way-list-status.js';
export default {
	data() {
		return {
			emptyType: 'order',
			emptyShow: false,
			pagenum: 1,
			pagesize: 10,
			downOption: {
				auto: false // 不自动加载 (mixin已处理第一个tab触发downCallback)
			},
			upOption: {
				auto: false, // 不自动加载 
				noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
				empty: {
					tip: '~ 暂无订单 ~', // 提示
					btnText: '去逛逛'
				}
			},
			categoryId: '',
			orderList: [], //列表数据
			canIUseGetUserProfile: false,
			ewmimage: '',
		};
	},
	props: {
		i: Number, // 每个tab页的专属下标 (除了支付宝小程序必须在这里定义, 其他平台都可不用写, 因为已在MescrollMoreItemMixin定义)
		index: {
			// 当前tab的下标 (除了支付宝小程序必须在这里定义, 其他平台都可不用写, 因为已在MescrollMoreItemMixin定义)
			type: Number,
			default () {
				return 0;
			}
		},
		listTop: {
			type: Number,
			default () {
				return 10;
			}
		},
		skeyword: {
			type: String,
			default () {
				return '';
			}
		},
		tabObj: {
			type: Object,
			default () {
				return;
			}
		}
	},
	watch: {
		skeyword(newVal, oldVal) {
			if (newVal) {
				// this.mescroll.resetUpScroll()
			}
		}
	},
	created() {
		//加判断 编辑页来的，请求列表接口
		//this.getOrderListData();
		// #ifdef MP-WEIXIN
		if (wx.getUserProfile) this.canIUseGetUserProfile = true;
		// #endif
	},
	onShow(){
	 
	},
	methods: {
		getDepartBtnShow(rows){
			if(listStatus.getUploadLevelBtnShow(rows) == 1 || listStatus.getUploadLevelBtnShow(rows) == 2){
				return true;
			}
			return false;
		},
		getAllocationBtnShow(rows){
			if(listStatus.getUploadLevelBtnShow(rows) == 0){
				return true;
			}
			return false;
		},
		getSelect(row) {
			return listStatus.getSelect(row);
		},
		waybillStatus(rows) {
			return listStatus.status(rows);
		},
		getStatusP2(rows) {
			return listStatus.getStatusP2(rows);
		},
		getLevel(rows) {
			return listStatus.getLevel(rows);
		},
		getStatus(rows) {
			return listStatus.getStatus(rows);
		},
		getTransitStatus(rows) {
			return listStatus.getTransitStatus(rows);
		},
		getDestinationCity(rows) {
			return listStatus.getDestinationCity(rows);
		},
		getDisabledDel(rows) {
			return listStatus.getDisabledEdit(rows);
		},
		getDisabledEdit(rows) {
			return listStatus.getDisabledEdit(rows);
		},
		getDepartPic1(rows) {
			return listStatus.getDepartPic1(rows);
		},
		getDepartPic2(rows) {
			return listStatus.getDepartPic2(rows);
		},
		getArrivePic1(rows) {
			return listStatus.getArrivePic1(rows);
		},
		getAllocatePic1(rows) {
			return listStatus.getAllocatePic1(rows);
		},
		getAllocatePic2(rows) {
			return listStatus.getAllocatePic2(rows);
		},
		carLoading(e){
			this.$util.redirectTo('/pages/order/order-confirm/order-depart-confirm',e,null,'obj');
		},
		toDetail(item) {
			this.$util.redirectTo('/pages/order/order-detail/order-detail', {
				waybill_id: item.waybill_id,
				in_type: '1',
			});
		}, 
		/*下拉刷新的回调 */
		downCallback() {
			this.pagenum = 1;
			// this.pagesize = 10;
			this.mescroll.resetUpScroll();
		},
		/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
		upCallback(page) {
			this.pagenum = page.num;
			this.pagesize = page.size;
			this.getOrderListData();
		},
		//点击空布局按钮的回调
		emptyClick() {
			this.$util.redirectTo('/pages/index/index/index', {}, 'redirectTo');
		},
  
		getOrderListData(type) {
			if (!this.check.isLogin()) {
				return
			}
			let level = uni.getStorageSync(this.preutils.accountLevel);
			if (level == 2) {
				 this.getWaybillListData();
			} else if (level == 1) {
				 this.getWaybillListData();
			} else {
				 this.allocationListLoadData();
			}
		},
		getWaybillListData(type) {
			var data = {
				page: this.pagenum,
				page_size:this.pagesize, 
			};
			let level = uni.getStorageSync(this.preutils.accountLevel);
			if (level == 2) {
				data.status_p2= '100';  
			} else if (level == 1) {
				data.status= '300';  
			} else {
				data.status= '300'; 
			}
			this.emptyShow = false;
			this.http.sendRequest({
				api: this.api.order.waybllListApi,
				data: data,
				success: res => {
					this.emptyShow = true;
					this.emptyType = 'order';
					let newArr = [];
					let msg = res.message;
					if (res.code == '1' && res.data) {
						newArr = res.data.data;
					} else {
						this.$util.showToast({
							title: msg
						});
					}
					console.log(res)
					this.mescroll.endSuccess(newArr.length);
					//设置列表数据
					if (this.pagenum == 1) this.orderList = []; //如果是第一页需手动制空列表
					this.orderList = this.orderList.concat(newArr); //追加新数据
					if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				},
				fail: res => {
					this.emptyType = 'order';
					this.emptyShow = true;
					if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				}
			});
		},
 	 
		allocationListLoadData(e) {
			var data = {
				status: '500',
				page: this.pagenum,
				page_size:this.pagesize,
			};
			// console.log(this.check.isLogin())
			this.emptyShow = false;
			this.http.sendRequest({
				api: this.api.order.allocationList,
				data: data,
				success: res => {
					this.emptyShow = true;
					this.emptyType = 'order';
					let newArr = [];
					let msg = res.message;
					if (res.code == '1' && res.data) {
						newArr = res.data.data;
					} else {
						this.$util.showToast({
							title: msg
						});
					}
					console.log(res)
					this.mescroll.endSuccess(newArr.length);
					//设置列表数据
					if (this.pagenum == 1) this.orderList = []; //如果是第一页需手动制空列表
					this.orderList = this.orderList.concat(newArr); //追加新数据
					if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				},
				fail: res => {
					this.emptyType = 'order';
					this.emptyShow = true;
					if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				}
			});	 
		},
	}
};